/*
 * MainUI.java
 *
 * Created on 09/10/2011, 20:06:46
 */
package com.bcc.airlines.ui;

import com.bcc.airlines.app.Facade;
import com.bcc.airlines.patterns.Observador;
import javax.swing.JPanel;

/**
 * Janela principal
 * @author Serginho
 */
public class MainUI extends javax.swing.JFrame implements Observador {

    public MainUI(Facade fachada) {
        this.fachada = fachada;
        initComponents();
        initPanels();
        Switch(home);
    }

    /**
     * Retorna para a Home
     */
    public void Return() {
        Switch(home);
    }

    /**
     * Seleciona um modulo para ser exibido
     * @param module 
     */
    public void select(String module) {
        switch (module) {
            case "Config":
                Switch(config);
                break;
            case "Airports":
                Switch(airports);
                break;
            case "Airplanes":
                Switch(airplanes);
                break;
            case "Tickets":
                Switch(tickets);
                break;
            case "Help":
                Switch(help);
                break;
            case "Weather":
                Switch(weather);
                break;
            case "Flights":
                Switch(flights);
                break;
            default:
                Switch(home);
                break;
        }
    }

    /**
     * 
     * @return a fachada de metodos do sistema
     */
    public Facade getFachada() {
        return fachada;
    }

    /**
     * troca o painel visivel
     * @param panel 
     */
    private void Switch(JPanel panel) {
        showPanel.removeAll();
        showPanel.add(panel);
        showPanel.updateUI();
    }

    /**
     * Inicia os paineis com cada view de cada modulo do sistema
     */
    private void initPanels() {
        home = new HomeUI(this);
        config = new ConfigUI(this);
        airports = new AirportUI(this);
        airplanes = new AirplanesUI(this);
        tickets = new TicketUI(this);
        help = new HelpUI(this);
        weather = new WeatherUI(this);
        flights = new FlightsUI(this);        
    }

    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        showPanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bcc/airlines/ui/images/logo.png"))); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bcc/airlines/ui/images/close.png"))); // NOI18N
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bcc/airlines/ui/images/help.png"))); // NOI18N
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });

        showPanel.setOpaque(false);
        showPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 50));

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bcc/airlines/ui/images/config.png"))); // NOI18N
        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel4MouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(showPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 908, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 398, Short.MAX_VALUE)
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel2)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3)
                    .add(jLabel4))
                .add(18, 18, 18)
                .add(showPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
                .add(46, 46, 46))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked
    select("Help");
}//GEN-LAST:event_jLabel3MouseClicked

private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
    fachada.quit();
}//GEN-LAST:event_jLabel2MouseClicked

private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked
    select("Config");
}//GEN-LAST:event_jLabel4MouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel showPanel;
    // End of variables declaration//GEN-END:variables
    private Facade fachada;
    private JPanel home, config, help,
            airplanes, airports, tickets,
            weather, flights;

    @Override
    public void atualiza() {
        
    }
}
